<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>XXX图书管理系统</title>
</head>
<body>

<a href="index.php">返回首页</a><br>
<button type="button" onclick="history.go(-1);">返回上一页</button>
<?php
try {
    $dsn = 'mysql:dbname=Library;host=127.0.0.1';
    $user = 'root';
    $password = '123456';
    $db = new PDO($dsn, $user, $password);
    $statement1=$db->prepare('select * from Users WHERE ID=:id');
    $statement1->execute(['id'=>$_GET['id']]);
    $result1=$statement1->fetch();

    $statement2=$db->prepare('select Users.Name as UserName,Users.ID as UserID,Record.Book as BookID,Book.Name as BookName,BorrowTime,ReturnTime,Record.Status as RecordStatus from Users,Record,Book WHERE Users.ID=Record.User and Record.Book=Book.ID and Users.ID=:userid');
    $statement2->execute([':userid'=>$_GET['id']]);
    $result2=$statement2->fetchAll();



} catch (PDOException $e) {
    var_dump($e->getMessage());
    die('程序出错');
}


?>



<?php
if(empty($result1)){
    echo"404用户不存在";
}else{
    echo "<P>用户卡号：".$result1['ID']."</P>";
    echo "<P>用户姓名：".$result1['Name']."</P>";
    echo "<P>用户类型：".$result1['UsrType']."</P>";
    echo "<P>借书记录：</P>";
    if(!empty($result2)){
        foreach ($result2 as $value){
            echo "<li>";
            $status=(int)($value['RecordStatus'])?'已还':'未还';
            echo "<p>书号：".$value['BookID']."<br>书名：".$value['BookName']."<br>借书时间：".$value['BorrowTime']."<br>还书时间：".$value['ReturnTime']."<br>状态：".$status."</p>";
            echo "</li>";
            }
    }



}
?>





</body>
</html>